{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6eba4a65-4a39-4136-8db2-97da1db90acc",
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = \"human2.fna\"\n",
    "data_file = open(filename, 'r')\n",
    "\n",
    "out_filename = \"human2.fna.line\"\n",
    "out_file = open(out_filename, 'w')\n",
    "\n",
    "max_line_len = 1000 #1000个字母一行数据\n",
    "\n",
    "text = \"\"\n",
    "for line in data_file:\n",
    "    line = line.strip()\n",
    "    if line.find(\">\") != 0: #去掉标题行\n",
    "        line = line.upper()\n",
    "        line = line.replace(\" \",\"\").replace(\"N\",\"\") #去掉N和空格\n",
    "        text = text + line\n",
    "        if len(text) > max_line_len:\n",
    "            text = text.strip()\n",
    "            out_file.write(text+\"\\n\")\n",
    "            text = \"\" #clear text\n",
    "#last line\n",
    "if len(text) <= max_line_len:\n",
    "    pass #不要了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60058335-0b18-48e9-bf4a-25bcd48e5441",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
